package com.ruoyi.durian.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.durian.domain.LlThali;
import com.ruoyi.durian.domain.LlThaliRecord;
import com.ruoyi.durian.domain.vo.ThaliByVo;
import com.ruoyi.durian.mapper.LlThaliMapper;
import com.ruoyi.durian.service.LlThaliRecordService;
import com.ruoyi.durian.mapper.LlThaliRecordMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
* @author lenovo
* @description 针对表【ll_thali_record(优惠券模块-购买套餐记录表)】的数据库操作Service实现
* @createDate 2024-07-26 16:17:16
*/
@Service
public class LlThaliRecordServiceImpl extends ServiceImpl<LlThaliRecordMapper, LlThaliRecord>
    implements LlThaliRecordService{

    @Resource
    private LlThaliRecordMapper llThaliRecordMapper;

    @Resource
    private LlThaliMapper llThaliMapper;

    /**
     * 套餐购买记录
     *
     * @return
     */
    @Override
    public List<LlThaliRecord> thaliBuyList() {
        Integer userId = 1204;
        LambdaQueryWrapper<LlThaliRecord> qw = new LambdaQueryWrapper<>();
        qw.eq(LlThaliRecord::getUserId,userId);
        return list(qw);
    }

    /**
     * 购买套餐
     *
     * @return
     */
    @Override
    public AjaxResult thaliBuy(Integer id) {
        if (id == null) {
            return AjaxResult.error("请选择套餐");
        }
        // 生成订单
        LlThali thali = llThaliMapper.selectById(id);
        if (thali == null) {
            return AjaxResult.error("套餐不存在");
        }

        LlThaliRecord record = new LlThaliRecord();
        record.setThaliName(thali.getName());
        record.setThaliId(thali.getId());
        record.setPirce(thali.getMoney());
        record.setMaxMoney(thali.getMaxMoney());
        record.setCouponNum(thali.getCouponNum());
        record.setCreateTime(new Date());
        record.setUpdateTime(new Date());
        record.setUserId(1204);
        record.setIsDelete(0);

        save(record);

        return AjaxResult.success();
    }
}




